
var page = 1;
var rows = 20;

var urlComAction = 'http://47.94.2.29/dam/app/';

function mpms_ajax(data, meth,callback) {
	 data.appid = localStorage.getItem('uuid');
	 data.token = localStorage.getItem('token');
	mui.ajax(urlComAction + meth, {
		data: data,
		dataType: 'json', //服务器返回json格式数据
		type: 'post', //HTTP请求类型 
		timeout: 20000, //超时时间设置为20秒；
		beforeSend: function() {
			plus.nativeUI.showWaiting('加载中...');
		},
		complete: function() {
			plus.nativeUI.closeWaiting();
		},
		success: function(returnValues) {
			if(!isNull(returnValues)){
				if(returnValues.status == '0'){
					callback(returnValues);
				}else{
				    mui.toast(returnValues.msg);	
				}
			}else{
				mui.toast("请求失败");
			}
		},
		error: function(xhr, type, errorThrown) {
			plus.nativeUI.closeWaiting();
			mui.toast("网络连接不可用，请稍后再试。");
		}
	});

}

function mpms_ajax_noWaiting(data,meth,callback) {
	data.IMEI = localStorage.getItem('uuid');
	data.token = localStorage.getItem('token');
	mui.ajax(urlComAction + meth, {
		data: data,
		dataType: 'json', //服务器返回json格式数据
		type: 'post', //HTTP请求类型 
		timeout: 20000, //超时时间设置为20秒；
		success: function(returnValues) {
		   if(!isNull(returnValues)){
				if(returnValues.status == '0'){
					callback(returnValues);
				}else{
				 mui.toast(returnValues.msg);	
				}
			}else{
				mui.toast("请求失败。");
			}
		},
		error: function(xhr, type, errorThrown) {
			mui.toast("网络连接不可用，请稍后再试。")
		}
	});

}


function gotoPage(urls) {
	mui.openWindow({
		url: urls,
		waiting: {
			autoShow: false //自动显示等待框，默认为true
		}
	});
	
}

function gotoSumPage(ulr) {
	if(ulr) {
		mui.openWindow({
			url: ulr.split('?')[0],
			waiting: {
				autoShow: false //自动显示等待框，默认为true
			},
			extras: {
				data: ulr.split('?')[1],
				path: ulr.split('?')[2],
				thParam: ulr.split('?')[3],
			}

		});

	}
}


//判断为空
function isNull(str) {
	if(str == 'undefined') {
		return true;
	} else if(str == null) {
		return true;
	} else if(str == 'null') {
		return true;
	} else if(str.length <= 0) {
		return true;
	} else if(str.toString().replace(/(^\s*)|(\s*$)/g, "") == "") {
		return true;
	} else {
		return false;
	}
}

function gettoken(){
	
	var params = {
				'user':localStorage.getItem('useid'),
				'pswd':localStorage.getItem('pswd')
			}
			mpms_ajax_noWaiting(params,'getToken',function(data){
				localStorage.setItem('token',data.token);
			    mui.openWindow({
						url: 'view/main_tab.html',
						waiting: {
							autoShow: false //自动显示等待框，默认为true
						}
		               });
	          });
        }

			
				//注销
function logout() {
		var	wvs = plus.webview.all(); // 获取所有Webview窗口
		var launchview = plus.webview.getLaunchWebview(); //获取首页(登录)
			var btn = ["确定", "取消"];
			mui.confirm('确认要退出账号？', '', btn, function(e) {
				if(e.index == 0) {
						
						for(var i = 0; i < wvs.length; i++) {

							if(wvs[i].getURL() == launchview.getURL())
								continue;
								
							plus.webview.close(wvs[i]);
						}

						localStorage.clear();

				}
			});
		}

     function getPagetoken(){
	             var params = {
								'user':localStorage.getItem('useid'),
								'pswd':localStorage.getItem('pswd')
							}
							mpms_ajax_noWaiting(params,'getToken',function(data){
								localStorage.setItem('token',data.token);
					     });
             }
	/*10位时间戳获取时间 */
	function getdate(time){
		let date = new Date(parseInt(time) * 1000);
		let y = date.getFullYear(); 
		let m = date.getMonth() + 1; 
		m = m < 10 ? ('0' + m) : m;
		let d = date.getDate(); 
		d = d < 10 ? ('0' + d) : d;
		return y + '-' + m + '-' + d  ;
		
	}		 
